package com.wiscamp.ninechapters.problems.infrastructure.gateway;

import com.wiscamp.ninechapters.panels.application.services.DictionaryAppService;
import com.wiscamp.ninechapters.problems.domain.gateway.DictionaryGateway;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class DictionaryGatewayImpl implements DictionaryGateway {

    private DictionaryAppService dictionaryAppService;

    public DictionaryGatewayImpl(DictionaryAppService dictionaryAppService) {
        this.dictionaryAppService = dictionaryAppService;
    }

    public int getDictionaryIdByCode(String dictionaryCode, long appId) {
        var dictionary = dictionaryAppService.getDictionaryByCode(appId, dictionaryCode);
        var id =  Objects.isNull(dictionary) ? 0 : dictionary.getDictionaryId();
        return (int)id;
    }

}
